{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "my = pd.read_csv('maoyanfilms_clean.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "  t_list = [] #存放电影类型的列表\n",
    "for i in range(0,len(my['films_type'])):\n",
    "   if type(my['films_type'][i])== str:\n",
    "    s_t = my['films_type'][i].split(',')\n",
    "    for j in s_t:\n",
    "        if j not in t_list:\n",
    "            t_list.append(j)  \n",
    "t_list.remove(' 青春 励志 爱情 ')\n",
    "t_list.remove('  ')\n",
    "t_list.remove(' 惊悚；恐怖；悬疑；爱情 ')\n",
    "t_list.remove(' 灵异/喜剧/悬疑 ')\n",
    "t_list.remove(' 爱情 恐怖 ')\n",
    "t_list.remove(' 爱情 / 喜剧 / 青春 ')\n",
    "\n",
    "type_range_list = t_list[0:25]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Users\\80423\\anaconda3\\lib\\site-packages\\ipykernel_launcher.py:6: RuntimeWarning: invalid value encountered in double_scalars\n",
      "  \n"
     ]
    }
   ],
   "source": [
    "f_t_average_score=[0]*len(type_range_list)\n",
    "for i in range(0,len(type_range_list)):\n",
    "    s_s = my[my['films_type']==type_range_list[i]]['films_score']\n",
    "    total_score = s_s.sum()\n",
    "    total_num = s_s.count()\n",
    "    f_t_average_score[i] = round((total_score/total_num),2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Scatter\n",
    "c = (\n",
    "    Scatter()\n",
    "    .add_xaxis(list(type_range_list))\n",
    "    .add_yaxis(\"平均评分\",f_t_average_score)\n",
    "    .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title=\"各类型平均评分\"),\n",
    "    )\n",
    "    .render(\"不同类型电影平均分.html\")\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
